<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.org/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Title</title>
    <link rel="stylesheet" href="/resources/layui/css/layui.css">
</head>
<body>
<script src="/resources/layui/layui.js"></script>
<script type="text/javascript" src="/resources/js/jquery-1.12.3.min.js"></script>

<script th:inline="none">
    //一般直接写在一个js文件中
    layui.use(['layer', 'form','table'], function(){
        var layer = layui.layer
            ,form = layui.form
            ,table = layui.table
            ,$=layui.jquery;
        var id=$("#unitid").val();
        //根据父页面传来的id获取车辆信息并回填
        $.ajax({
            type:"get",
            url:"/unit/selectUnitById",
            data:{unitid:id},
            success:function(resp){
                console.log(resp.data.unit);
                var unit=resp.data.unit;
                $(":text[name=name]").val(unit.name);
                $("#unittypeid").val(unit.unittype.id);
                $(":text[name=telephone]").val(unit.telephone);
                $(":text[name=contact]").val(unit.contact);
                $(":text[name=information]").val(unit.information);
                $(":radio[name=available]").val(unit.available);
            }
        });

        //单位类型下拉菜单
        $.ajax({
            type:'get',
            url:'/dictionary/getUnittype',
            success:function (res) {
                var unittypeList=res.data.unittypeList;
                if(unittypeList.length>0){
                    for(var i=0;i<unittypeList.length;i++){
                        var unittype=unittypeList[i];
                        var sele='';
                        if(unittype.id==$("#unittypeid").val()){
                            sele='selected';
                        }
                        $("#unittypeid").append("<option value='"+unittype.id+"' selected='"+sele+"'>"+unittype.name+"</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select")
            }
        });
    });
    var callbackdataUpdateUnit=function(){
        var forms = $("#formUpdate").serialize();
        return forms;
    }
</script>

<form class="layui-form" action="" id="formUpdate">
    <input type="hidden" id="unitid" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label">单位名称：</label>
        <div class="layui-input-block">
            <input type="text" name="name" required  lay-verify="required" placeholder="请输入单位名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单位类型：</label>
        <div class="layui-input-block">
            <select id="unittypeid" name="unittype" lay-verify="required">
                <option value="0">请选择单位类型</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电话：</label>
        <div class="layui-input-block">
            <input type="text" name="telephone" required  lay-verify="required" placeholder="请输入电话号码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系人：</label>
        <div class="layui-input-block">
            <input type="text" name="contact" required  lay-verify="required" placeholder="请输入联系人姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注：</label>
        <div class="layui-input-block">
            <input type="text" name="information" required  lay-verify="required" placeholder="请输入备注" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态：</label>
        <div class="layui-input-block">
            <input type="radio" name="available" value="1" title="启用"  checked>
            <input type="radio" name="available" value="0" title="禁用">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

</body>
</html>